"""
//body//a[text()="文库"]
//body//a[@class="tabItem baike "]
//p[last()]
//p[last()-1]
//p[1]
//p[position()<=2] # 1-2
//p[position()>=last()-2] # 最后3个
//*[@type="text/javascript"][1]
或者
//script | //link
** 选择某个节点的父节点，css做不到**
//*[@id="kw"]/..
所有后续兄弟节点
//*[@id="kw"]/following-sibling::*
//*[@id="kw"]/following-sibling::span
所有前续兄弟节点，css不方便**
//*[@id="kw"]/preceding-sibling::*
css与xpath组合选择注意
主体不是wb，而是we element对象，前面要加.;这是个坑
"""


from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import  By
from selenium.common.exceptions import NoSuchElementException
wd = webdriver.Chrome(service=Service(r'/Users/tonywu/downloads/Mess/chromedriver/chromedriver'))
wd.get("http://www.baidu.com")
try:

    element = wd.find_element(By.CSS_SELECTOR,'div#lg')
    # element.find_element(By.XPATH, "//i")
    els=element.find_elements(By.XPATH, ".//img")
    print(len(els))
    print(element.get_attribute("innerHTML"))


except NoSuchElementException as e:
    print(e.msg)
input()